#![cfg_attr(not(feature = "std"), no_std)]

use liquid::storage;
use liquid_lang as liquid;

#[liquid::contract]
mod asset {
    use liquid_primitives::types::Address;

    use super::*;

    /// Defines the state variables of your contract.
    #[liquid(storage)]
    struct Asset {
        issuer: storage::Value<Address>
        balances: storage::Mapping<Address, u64>
    }

    /// Defines the methods of your contract.
    #[liquid(methods)]
    impl Asset {
        /// Defines the constructor which will be executed automatically when the contract is
        /// under deploying. Usually constructor is used to initialize state variables.
        ///
        /// # Note
        /// 1. The name of constructor must be `new`;
        /// 2. The receiver of constructor must be `&mut self`;
        /// 3. The visibility of constructor must be `pub`.
        /// 4. The constructor should return nothing.
        /// 5. If you forget to initialize state variables, you
        ///    will be trapped in an runtime-error for attempting
        ///    to visit uninitialized storage.
        pub fn new(&mut self, owner: Address) {
            self.balance.initialize();
            self.issuer.initialize(owner);
        }

        pub fn issue(&mut self, receiver: Address, amount: u64)->bool{
            let caller = self.env().caller();
            assert_eq!(caller.as_bytes(), self.issuer.as_bytes(), "issuer isn't match !");

        }
        pub fn transfer(&mut self, receiver: Address, amount: u64){}
    }

    /// Unit tests in Rust are normally defined within such a `#[cfg(test)]`
    /// module and test functions are marked with a `#[test]` attribute.
    /// The below code is technically just normal Rust code.
    #[cfg(test)]
    mod tests {
        /// Imports all the definitions from the outer scope so we can use them here.
        use super::*;
    }
}
